<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/27 0027
 * Time: 09:32
 */

namespace app\admin\controller;


use think\Loader;
use think\Request;

class Message extends Base
{
    protected $_Message;
    public function __construct(Request $request = null){
        parent::__construct($request);
        $this->_Message = new \app\model\model\Message();
    }
    public function lists(){
        return $this->fetch();
    }
    public function getList(){
        $where = [];
        $name = input('name');
        $type = input('type');
        if($name){
            $where['name'] = ['like',"%$name%"];
        }
        if($type){
            $where['status'] = ['like',"%$type%"];
        }
        $data = $this->_Message->getList($where,input('limit'));
        foreach ($data as $v){
            $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
               switch ($v['status'])
               {
                   case 1:
                       $v['status']="未审核";
                       break;
                   case 2:
                       $v['status']="已审核";
                       break;
                   default:
                       $v['status']="无效订单";
               }

        }
        $list = $data->toArray();
        echo json_echo($list);
    }
    /**
     * 回复
     * */
    public function reply(){
        if(!Request::instance()->post()){
            $data = $this->_Message->getOne(input('id'));
            $this->assign('data',$data);
            return $this->fetch();
        }else{
            $data = [
                'admin_reply'=>input('admin_reply'),
            ];
            $re = $this->_Message->up(['id'=>input('id')],$data);
            if($re){
                return json_echo_msg(200,'回复成功');
            }else{
                return json_echo_msg(500,'回复失败');
            }
        }
    }
    /**
     * 审核
     * */
    public function audit(){

        $re = $this->_Message->up(['id'=>input('id')],['status'=>2]);
        if($re){
            return json_echo_msg(200,'审核成功');
        }else{
            return json_echo_msg(500,'已审核');
        }
    }
    /**
     * 添加
     * */
    public function add(){
        if(!Request::instance()->post()){
            return $this->fetch();
        }else{

            $data = [
                'name'=>input('name'),
                'details'=>input('editorValue'),
                'create_time'=>time(),
            ];
            $re = $this->_Message->add($data);
            if($re){
                return json_echo_msg(200,'添加成功');
            }else{
                return json_echo_msg(500,'添加失败');
            }
        }
    }
    /**
     * 修改
     * */
    public function up(){
        if(!Request::instance()->post()){
            $data = $this->_Message->getOne(input('id'));
            $this->assign('data',$data);
            return $this->fetch();
        }else{
            $data = [
                'name'=>input('name'),
                'details'=>input('editorValue'),
            ];
            $re = $this->_Message->up(['id'=>input('id')],$data);
            if($re){
                return json_echo_msg(200,'修改成功');
            }else{
                return json_echo_msg(500,'修改失败');
            }
        }
    }
    /**
     * 获取一条数据
     * */
    public function getOne(){
        $data = $this->_Message->getOne(input('id'));
        echo json_echo_msg(200,'成功',$data);
    }
    /**
     * 删除
     * */
    public function del(){
        $re = $this->_Message->del(['id'=>input('id')]);
        if($re){
            return json_echo_msg(200,'删除成功！');
        }else{
            return json_echo_msg(400,'删除失败！');
        }
    }
    /**
     * 批量删除
     * */
    public function delAll(){
        $re = $this->_Message->delAll(input()['data']);
        if($re){
            return json_echo_msg(200,'删除成功！');
        }else{
            return json_echo_msg(400,'删除失败！');
        }
    }
    public function email(){
        email_send('zhouzhenghui_php@163.com',false,'通知邮件','
<div class="_email" style="padding: 0 20px;">
    <div class="row">
        <div class="col-lg-12 col-xs-12 col-sm-12 col-md-12" style="">
          <div class="col-lg-4 col-xs-12 col-sm-12 col-md-12" style="position: absolute;left:0; top:0px; right:0; bottom: 0; margin: auto; ">
            <div class="_main_top">
              <div class="_logo" style="background: #aa0000;padding: 10px 10px;border-top-right-radius: 6px;border-top-left-radius: 6px;">
                <div class="pic" style="background: url(http://jx.biaofan.cc/static/logo.jpg) center center no-repeat;background-size: cover;width: 146px;height: 36px;float: left;"></div>
                <div style="float: right ;color: #c44d4d;font-size: 16px;">尾号<span style="display: inline-block;color: #fff;font-size: 20px;">4966</span></div>
                <div style="clear: both;"></div>
              </div>
            </div>
            <div class="_main_bottom" style="padding: 10px 20px;border: 1px #b1b1b1 solid;border-bottom-right-radius: 6px;border-bottom-left-radius: 6px;">
              <div style="margin-bottom: 20px;">
                <p style="font-size: 16px;">尊敬XXX先生</p>
                <p style="font-size: 16px;">以下是您的信用卡每日消费明细：</p>
              </div>
              <p style="font-size: 20px;">2018/07/02消费明细</p>
              <div class="_main_main">
                <p style="float: left;font-size: 16px;">12:11</p>
                <div style="float: left;margin-left: 20px;">
                  <h3 style="margin-top: 2px;">CNY&nbsp;50.00</h3>
                  <p>消费&nbsp;微信支付：泊寓·生产路店</p>
                </div>
                <div style="clear: both;"></div>
              </div>
            </div>
          </div>
        </div>
    </div>
  </div>
  <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  ');
    }
}
